<!--
 * @Description: 意见反馈
 * @version: 电子名片2.0
 * @Author: 尹鑫
 * @Date: 2020-12-02 09:31:17
 * @LastEditors: 尹鑫
 * @LastEditTime: 2020-12-16 10:26:56
-->
<template>
  <div class="mainbox">
    <adminTable ref="refTable" :form-inline="formInline" :api-fun="opinionList" :table-column="tableColumn" :table-data.sync="tableData">
      <!-- 搜索插槽 -->
      <template slot="search">
        <el-form-item>
          <el-input v-model="formInline.keyword" placeholder="意见编号、反馈人" clearable />
        </el-form-item>
        <el-form-item>
          <el-select v-model="formInline.feedbackSource" placeholder="来源">
            <el-option v-for="(item, index) in areaList" :key="index" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="formInline.feedbackStatus" placeholder="状态">
            <el-option v-for="(item, index) in statusList" :key="index" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
      </template>
      <!-- 来源插槽 -->
      <template slot="feedbackSource" slot-scope="scope">
        <span v-if="scope.value.feedbackSource === '0'">企业端</span>
        <span v-else>用户端</span>
      </template>
      <!-- 状态插槽 -->
      <template slot="feedbackStatus" slot-scope="scope">
        <span v-if="scope.value.feedbackStatus === '0'" style="color: #F56C6C">待回复</span>
        <span v-else style="color: #67C23A">已回复</span>
      </template>
      <!-- 操作插槽 -->
      <template slot="operat" slot-scope="scope">
        <el-button v-if="scope.value.feedbackStatus === '1'" type="text" size="small" @click="handleClick(scope.value)">意见详情</el-button>
        <el-button v-else type="text" size="small" @click="handleClick(scope.value)">意见回复</el-button>
      </template>
    </adminTable>
    <!-- 意见详情 or 意见回复模态框 -->
    <el-dialog :title="form.feedbackStatus === '1' ? '意见详情' : '意见回复'" :close-on-click-modal="false" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="意见内容：" label-width="120px">{{ form.feedbackContent }} </el-form-item>
        <el-form-item label="反馈图片：" label-width="120px">
          <el-image v-for="(item, index) in form.feedbackPicture" :key="index" style="margin-right:10px; width: 100px; height: 100px" :src="item" :preview-src-list="form.feedbackPicture" />
        </el-form-item>
        <el-form-item label="回复内容：" label-width="120px">
          <el-input v-model="form.replyContent" type="textarea" maxlength="500" :disabled="Boolean(form.feedbackStatus === '1')" show-word-limit :autosize="{ minRows: 4, maxRows: 4}" autocomplete="off" />
        </el-form-item>
      </el-form>
      <div v-if="form.feedbackStatus === '0'" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFeedback()">提交</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
      <div v-else slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import adminTable from '@/components/admin/admin-table'
import { opinionList, opinionDetail, opinionReply } from '@/api/opinion'
import { tableColumn, areaList, statusList } from './listConfig'
export default {
  components: {
    adminTable
  },
  data() {
    return {
      tableColumn,
      tableData: [],
      formInline: {
        keyword: '',
        feedbackSource: '',
        feedbackStatus: ''
      },
      areaList,
      statusList,
      opinionList,
      dialogFormVisible: false,
      form: {}
    }
  },
  methods: {
    async handleClick(e) {
      const { data } = await opinionDetail(e)
      this.dialogFormVisible = true
      data.feedbackPicture = data.feedbackPicture.split(',')
      this.form = {
        ...data,
        ...e
      }
    },
    async submitFeedback() {
      const { data } = await opinionReply({
        feedbackId: this.form.feedbackId,
        replyContent: this.form.replyContent
      })
      this.dialogFormVisible = false
      if (data) {
        this.$message({
          message: '操作成功',
          type: 'success'
        })
        this.$refs.refTable.getList()
      } else {
        this.$message.error('操作失败')
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
